/**
 * Created by Administrator on 2018/5/4.
 */
define(function (require,exports,module) {
    require("../../../lib/fullcalendar/css/all.css");
    require("../../../lib/fullcalendar/fullcalendar.min.css");
    // require("../../../lib/fullcalendar/fullcalendar.print.min.css");

    require("../../../lib/fullcalendar/scheduler.min.css");
     require("../../../lib/fullcalendar/bootstrap.min.css");
    require("./dutyOfWeek.scss")

    var sTpl = require("./template.html");
    var VueComponent = Vue.extend({
        props:['parentData'],
        template: sTpl,
        methods:{
            initQueryParam:function () {
                var mo =  moment();
                mo.week(mo.week()-1)
                var startDate =mo.format("YYYY-MM-DD");
                var mo2 =  moment();
                var endDate = mo2.week(mo2.week+1);
                var endDate = mo2.format("YYYY-MM-DD");
                this.startDate = startDate;
                this.endDate = endDate;

            },
             loadJs:function () {
                var $this = this;
                 require.async("../../../lib/fullcalendar/moment.min.js",function() {
                     require.async("../../../lib/fullcalendar/fullcalendar.min.js", function () {
                         require.async("../../../lib/fullcalendar/locale/zh-cn.js", function () {
                             require.async("../../../lib/fullcalendar/scheduler.min.js", function () {
                                 $this.jsLoading=false;
                             })
                         })
                     })
                 })

              }

        },
        watch:{
            jsLoading:function(ov,nv){

                function initThemeChooser(settings) {
                    var isInitialized = false;
                    var $currentStylesheet = $();
                    var $loading = $('#loading');
                    var $systemSelect = $('#theme-system-selector select')
                        .on('change', function() {
                            setThemeSystem(this.value);
                        });

                    setThemeSystem($systemSelect.val());


                    function setThemeSystem(themeSystem) {
                        var $allSelectWraps = $('.selector[data-theme-system]').hide();
                        var $selectWrap = $allSelectWraps.filter('[data-theme-system="' + themeSystem +'"]').show();
                        var $select = $selectWrap.find('select')
                            .off('change') // avoid duplicate handlers :(
                            .on('change', function() {
                                setTheme(themeSystem, this.value);
                            });

                        setTheme(themeSystem, $select.val());
                    }


                    function setTheme(themeSystem, themeName) {
                        var stylesheetUrl = generateStylesheetUrl(themeSystem, themeName);
                        var $stylesheet;

                        function done() {
                            if (!isInitialized) {
                                isInitialized = true;
                                settings.init(themeSystem);
                            }
                            else {
                                settings.change(themeSystem);
                            }

                            showCredits(themeSystem, themeName);
                        }

                        if (stylesheetUrl) {
                            $stylesheet = $('<link rel="stylesheet" type="text/css" href="' + stylesheetUrl + '"/>').appendTo('head');
                            $loading.show();

                            whenStylesheetLoaded($stylesheet[0], function() {
                                $currentStylesheet.remove();
                                $currentStylesheet = $stylesheet;
                                $loading.hide();
                                done();
                            });
                        } else {
                            $currentStylesheet.remove();
                            $currentStylesheet = $();
                            done();
                        }
                    }


                    function generateStylesheetUrl(themeSystem, themeName) {
                        if (themeSystem === 'jquery-ui') {
                            return 'https://code.jquery.com/ui/1.12.1/themes/' + themeName + '/jquery-ui.css';
                        }
                        else if (themeSystem === 'bootstrap3') {
                            if (themeName) {
                                return 'https://bootswatch.com/3/' + themeName + '/bootstrap.min.css';
                            }
                            else { // the default bootstrap theme
                                return 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css';
                            }
                        }
                        else if (themeSystem === 'bootstrap4') {
                            if (themeName) {
                                return 'https://bootswatch.com/4/' + themeName + '/bootstrap.min.css';
                            }
                            else { // the default bootstrap4 theme
                                return 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css';
                            }
                        }
                    }


                    function showCredits(themeSystem, themeName) {
                        var creditId;

                        if (themeSystem === 'jquery-ui') {
                            creditId = 'jquery-ui';
                        }
                        else if (themeSystem === 'bootstrap3') {
                            if (themeName) {
                                creditId = 'bootstrap-custom';
                            }
                            else {
                                creditId = 'bootstrap-standard';
                            }
                        }

                        $('.credits').hide()
                            .filter('[data-credit-id="' + creditId + '"]').show();
                    }


                    function whenStylesheetLoaded(linkNode, callback) {
                        var isReady = false;

                        function ready() {
                            if (!isReady) { // avoid double-call
                                isReady = true;
                                callback();
                            }
                        }

                        linkNode.onload = ready; // does not work cross-browser
                        setTimeout(ready, 2000); // max wait. also handles browsers that don't support onload
                    }
                }

                initThemeChooser({

                    init: function(themeSystem) {
                        $('#calendar').fullCalendar({
                            themeSystem: themeSystem,
                            header: {
                                left: 'prev,next today',
                                center: 'title',
                                right: 'month,agendaWeek,agendaDay,listMonth'
                            },
                            defaultDate: '2018-03-12',
                            weekNumbers: true,
                            navLinks: true, // can click day/week names to navigate views
                            editable: true,
                            eventLimit: true, // allow "more" link when too many events
                            events: [
                                {
                                    title: 'All Day Event',
                                    start: '2018-03-01'
                                },
                                {
                                    title: 'Long Event',
                                    start: '2018-03-07',
                                    end: '2018-03-10'
                                },
                                {
                                    id: 999,
                                    title: 'Repeating Event',
                                    start: '2018-03-09T16:00:00'
                                },
                                {
                                    id: 999,
                                    title: 'Repeating Event',
                                    start: '2018-03-16T16:00:00'
                                },
                                {
                                    title: 'Conference',
                                    start: '2018-03-11',
                                    end: '2018-03-13'
                                },
                                {
                                    title: 'Meeting',
                                    start: '2018-03-12T10:30:00',
                                    end: '2018-03-12T12:30:00'
                                },
                                {
                                    title: 'Lunch',
                                    start: '2018-03-12T12:00:00'
                                },
                                {
                                    title: 'Meeting',
                                    start: '2018-03-12T14:30:00'
                                },
                                {
                                    title: 'Happy Hour',
                                    start: '2018-03-12T17:30:00'
                                },
                                {
                                    title: 'Dinner',
                                    start: '2018-03-12T20:00:00'
                                },
                                {
                                    title: 'Birthday Party',
                                    start: '2018-03-13T07:00:00'
                                },
                                {
                                    title: 'Click for Google',
                                    url: 'http://google.com/',
                                    start: '2018-03-28'
                                }
                            ]
                        });
                    },

                    change: function(themeSystem) {
                        $('#calendar').fullCalendar('option', 'themeSystem', themeSystem);
                    }

                });

            }
        },
        data:function () {


            return {
                startDate:"",
                endDate:"",
                flightInfoId:"",
                schedule:[],
                flightPlane:[],
                jsLoading:true
            };
        },
        mounted:function () {
            this.loadJs();
        }
        ,
        created:function (){

            var resourceCallback ;
        },
        activated:function () {
            messages.$emit('change','周值班表');
        }
    });
    module.exports = VueComponent;
    return VueComponent;
})